<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .title {
            font-size: 30px;
            width: 100%;
            height: 100%;
            background-color: yellow;
            margin-top: 50px;
        }
    </style>
</head>
<body>
<div class="title">h5页面</div>
</body>
</html>

<script>
    //需要接收端口
    var currentPort
    window.addEventListener("message",(event)=>{
        if(event.data =="trans_port"){
            currentPort = event.ports[0]
            if(currentPort){
                alert("获取端口成功！")
            }
        }
    })
    
</script>